import Mock from 'mockjs'
// 导入 模拟假数据的包
import {Random} from 'mockjs'

// 创建自定义 Mock 函数
Random.extend({
    // 自定义函数名: function 函数
    fruit: function () {
        const arr = ['榴莲', '波罗蜜', '椰子', '苹果', '菠萝', '释迦']
        return this.pick(arr)
    }
})
Mock.mock("/api/upload", "post", function (body) {
    console.log("body:", body)
    let pics = [
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.544YYnSoPCwjU2gRueTkkgHaHa?w=191&h=191&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.jts-kq9YlNz3Es-hF1x9-wHaHa?w=191&h=191&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.SpL-NmdQVSuvqgsYD1zP_wHaGB?w=235&h=191&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.4gwViDrPDvq8jq5p2eGTtAHaHa?w=190&h=191&c=7&r=0&o=5&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.X059GpXFZCzzD_wGT-8v6wHaHZ?w=190&h=191&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.v1i9Oqp3njmlR7hvfTPtLgAAAA?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.j8cNnCH_GGM_3h8v6-2IkQHaHa?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.MW20zAB8xeMvGQG8Ux0wkAHaHa?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.SK5LtgN1zAzfZai6JDDWfgHaHa?w=187&h=187&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.cAOfL4-0iHVh7XbnbPrmhgHaHZ?w=188&h=187&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.2QX7GhnasXGqLtPJewHTmQHaHa?w=250&h=187&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.HjjUASXHXJDM-0ClnAkXXgHaHb?w=187&h=187&c=7&r=0&o=5&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.-k56Uu3KSpg4pz3VdMagCgHaHZ?w=189&h=187&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.WZ22OF1CyFw2RqH1BUh81AHaHa?w=195&h=195&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.aJojHGRid2PGJagJod52VwHaHa?w=195&h=195&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.2GhbNO5eN-4sXtGRjMeMqAHaGq?w=216&h=195&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.TXInrEn92Qmt15Q11h34fwHaHa?w=195&h=195&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.jdtmis0ml5nRvISJIO6JywHaHa?w=194&h=195&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.tvj8BbX8V3PicnzUqo6ZwAHaHZ?w=212&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.PYCXRGpQCD2RApt2uGwBPQHaHa?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.0F1EUkcHs1CfySKqc2mnXgHaHa?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.9Vns1Bs_JFdiEHDNfoqz-QHaHa?w=211&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.ort0zDiopdTKseWTa8tjpgHaHa?w=210&h=211&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.5ryeRBo4c1Zaf093oCH0kgHaHa?w=210&h=210&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.ls5RmROLRZR0L1VB7ppmlgHaHR?w=214&h=210&c=7&r=0&o=5&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.8KaD0xMw4275RzRRALiyXwHaHX?w=210&h=210&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.C_u0BstSCWg9H1qAjg3E4AHaHa?w=209&h=210&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.sAiCiGYrRluulMkTFBaFIQHaHU?w=212&h=210&c=7&r=0&o=5&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.Lewbi9RySnBUr7airJjhSQHaHa?w=213&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.nYAKDlIfSAikt6i7b5ptHgHaKi?w=149&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.UOy52vv-0tEmzDS_2a_zEgHaN6?w=115&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.wGvNNE2LR6itLJpueyTWBAHaHL?w=219&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.tm6WK2JPevj3uX9Y7AH9oAHaHa?w=213&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.3vZy8d6Pift1OOdGuIKHbgHaHa?w=213&h=213&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.xd1WWBb-m52buq_6eZm_RgHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.6rgYblr91LhZogYBWrpyWwHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.RQ5zniPKQ3enH9By8AiqsgHaL_?w=118&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.Ujb2TGy4H9J1rsrEQ2D7TgHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.jfurQ_Iteni-S-WNnrva_AHaM1?w=115&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.T4BgNsMAVj3O2y3eNYHChgHaQD?w=115&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.3jo7hZoKSq-lLUabQ9fKwwHaHa?w=191&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.rWIqZ5kzZb9PxI-BlygT7QHaGq?w=240&h=216&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.vz_WG4Cx5wIlPiQhEjx4PwAAAA?w=216&h=216&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.k5KQzcxDvYFZN-cLesvN-wHaGp?w=241&h=216&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.3P8qIgIHeaQGWolYn34_ZgAAAA?w=216&h=216&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.GpR2EVniQ2vYVMO3JFwOfQAAAA?w=216&h=216&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.dTmQ2Q8y_oqjLKEWJRZfaAHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.nEyF4b3ZhMl-KOtCPDTxWwHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.QgDrENYMKunsdf_1LSEszwHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.v1TVKCsl3NwqiZIpEG_I7QHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.RR6081d7yzmAye6o8mNUggAAAA?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.57J0LeKVRrHZaqhgEJZmAwHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.OVUc0xMPnn-HpDZAzMJ06QHaHa?w=211&h=211&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.4p7oVBqkTVy-1eGwoxTqAAHaGq?w=234&h=211&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.KHUEBn8yZdYWXoLB9ETUwAHaGk?w=238&h=211&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.ExeCnsiSEh9mwk92HTHkOAHaHa?w=211&h=211&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.9QyDFTSoMBOHnvO09U8LFgHaGq?w=235&h=211&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.lPvhzRdEgHsGGEs9pdVcngHaHa?w=194&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.gEbIE6G8aAxKXDjZkIs5eQHaJl?w=150&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.z2i4maUWOax6XVk140ZCNQHaHa?w=194&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.sg1ydZL2IKoIKYs-jKeaFwHaHa?w=194&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.IMY9oorxm4x0uCQppf73KgHaHa?w=195&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.n38fyyUmb4b9jQ8awA3rrAHaHa?w=195&h=194&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.e45SA26hVk5LAE0BJzex3AHaHa?w=200&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.88r9c6KO5tItM_onL7fI0QHaHa?w=200&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.DI6LsB9y2PZjATfuGVanBwHaHa?w=200&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.lE8yNbaq12G8hPVkQzRWhAHaHa?w=200&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.tj6BgySrqJ-tHtB5ccuakgHaHa?w=200&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.oW-BC0189CbmK8HT2URvwwHaMF?w=122&h=200&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.r_lnB53P-AyexUWiHsWapgAAAA?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.qDYon_F13U6nm2k-ZcrZLQHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.I2TzY-C2RimzVN1-zXvhZwHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.41zLKGLopZhKenTcfAHEjwHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.MxHbaeiILqRuU8Wale0ewAHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.8dCsv6le9oT0e4xNJRcP4gHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.8SzgzXF1LeUV5nZNIFe1TgHaGq?w=204&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.3wcrFusODBo9gW9DZPCaHgHaHa?w=183&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.a0WTP9WSULxLvfhVilI8HAHaHa?w=184&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.7yrJEYanh4i_MtkCgY-U6QHaHa?w=184&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.eaY-Lwe5XxOFZ5_BneeyeQHaHa?w=184&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.GsM88dzijFrT4MfhAvs-KQHaHa?w=183&h=184&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.Kc08wyT6OKIjwWNAAMFQNAHaHQ?w=196&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.epZpjWyydR0NlXmEi160sgHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.2gnAOXFwuNIvgtxnggi_TQHaGL?w=230&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.HzwnOYX3KENl5R5SvDwdMQHaHU?w=194&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.A7CBpg6QXa6LvqyN0SizMgHaMN?w=117&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.5xMCwUkYclRK6Iv5TIQFtwHaHa?w=193&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse2-mm.cn.bing.net/th/id/OIP-C.qu-7grh02sT7Ab6qDvl7jAAAAA?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.KO5wgWGCWjcBqQtjkSKhiAHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.9WBRen1AYQggwBLYbLepZAAAAA?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.qd43FZbqrPWLFwA6xuFJMgHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.4khWnpqko9GUa8U0lwyQvgHaHa?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.2Lm0Ljw9WRl7KuDzp_KXyQAAAA?w=187&h=187&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.x2Mu8hMJFetVShEqwU-rewHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.4EqJ2O1bLqc5YkBEc7eH_gHaHa?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.H-8Avy7muvuuKJIX1IwvNQAAAA?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.K0G73obD3IFFExWv4-wHzwAAAA?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7",
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.tnriOTiVG412dMeH7ToDlQAAAA?w=192&h=192&c=7&r=0&o=5&dpr=3&pid=1.7"
    ]
    return {
        "code": "200",
        "data": {
            url: pics[Math.random() * pics.length | 0]
        }
    }
})
// 获取商品列表
Mock.mock('/api/goodslist', 'get', {
    status: 200,
    message: '获取商品列表成功！',
    'data|5-10': [
        {
            id: '@increment(1)',      // 自增的Id值
            // 'id|+1': 0,            // 这也是在模拟一个自增长的 Id 值
            name: '@cword(2, 8)',     // 随机生成中文字符串
            price: '@natural(2, 10)', // 自然数
            count: '@natural(100, 999)',
            img: '@dataImage(78x78)'  // 指定宽高图片
        }
    ]
})

// 添加商品
Mock.mock('/api/addgoods', 'post', function (option) {
    // 这里的 option 是请求相关的参数
    // 如果需要在返回的对象中再使用mock的语法，则需要再使用Mock.mock
    return Mock.mock({
        status: 200,
        message: '@cword(2,5)'
    })
})

// 根据Id获取商品信息
Mock.mock(/\/api\/getgoods/, 'get', function (option) {

    // 通过 正则 的 .exec() 函数，从字符串中提取需要的数据
    const res = /\/api\/getgoods/.exec(option.url)

    // 也可以通过字符串的split方法获取id
    // const urlId = option.url.split('/')[3]

    return Mock.mock({
        data: {
            id: res[1] - 0,
            // id: urlId,
            // 这里的@fruit()是前面自定义的mock函数
            name: '@fruit()',
            price: 2,
            count: 199,
            img: '@dataImage(78x78)'
        },
        status: 200,
        message: '获取商品成功！'
    })
})

